import 'package:flutter/material.dart';
import 'package:study_app/data/data_json.dart';
import 'package:study_app/models/models.dart';
import 'package:study_app/scenes/main_parts/reader_page.dart';
import 'package:study_app/utils/common.dart';

class DataList extends StatefulWidget {
  const DataList({Key? key}) : super(key: key);
  @override
  State<DataList> createState() => _DemoReaderState();
}

class _DemoReaderState extends State<DataList> {
  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("列表")),
      body: Container(
          color: const Color(0xfff5f5f5),
          child: Column(
            children: _makeListItems(),
          )),
    );
  }

  List<Widget> _makeListItems() {
    List<Widget> array = [];
    var data = speechDataList();
    for (var item in data) {
      var wi = _renderItem(item);
      array.add(wi);
    }
    return array;
  }

  Widget _renderItem(DataListModel item) {
    return InkWell(
        child: _view(item),
        onTap: () {
          Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (BuildContext context) =>
                      DemoReader(model: item)));
        });
  }

  Widget _view(DataListModel m) {
    return Container(
        alignment: Alignment.centerLeft,
        width: Common.screenWidth,
        decoration: const BoxDecoration(
            color: Colors.white,
            border:
                Border(bottom: BorderSide(width: 1, color: Color(0xffe5e5e5)))),
        child: _rowWidget(m),
        padding: const EdgeInsets.all(16),
        margin: const EdgeInsets.only(left: 10, top: 5, right: 10));
  }

  Widget _rowWidget(DataListModel m) {
    return Row(children: [
      Text(m.name)
    ]);
  }
}
